package com.minimalist.common.feign.fallback.lindi;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.tradeapplicationapprovefile.LindiTradeApplicationApproveFileVO;
import com.minimalist.common.entity.lindi.vo.tradeapplicationapprovefile.TradeApplicationApproveFileQueryVO;
import com.minimalist.common.feign.client.lindi.LindiTradeApplicationApproveFileFeignClient;
import com.minimalist.common.feign.config.BaseFallbackFactory;
import com.minimalist.common.response.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * 林地交易申请审批文件 Feign 客户端降级工厂
 * 使用FallbackFactory可以获取到异常信息，便于问题排查
 *
 * @author minimalist
 */
@Component
public class LindiTradeApplicationApproveFileFeignClientFallbackFactory extends BaseFallbackFactory<LindiTradeApplicationApproveFileFeignClient>{
    private static final Logger log = LoggerFactory.getLogger(LindiTradeApplicationApproveFileFeignClientFallbackFactory.class);


    @Override
    public LindiTradeApplicationApproveFileFeignClient create(Throwable cause){
        return new LindiTradeApplicationApproveFileFeignClient(){
            @Override
            public R<?> addTradeApplicationApproveFile(LindiTradeApplicationApproveFileVO tradeApplicationApproveFileVO){
                logServiceUnavailable("添加交易申请审批文件", tradeApplicationApproveFileVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "添加交易申请审批文件失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deleteTradeApplicationApproveFileByApproveFileId(
                    Long approveFileId){
                logServiceUnavailable("删除交易申请审批文件", approveFileId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "删除交易申请审批文件失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> updateTradeApplicationApproveFileByApproveFileId(
                    LindiTradeApplicationApproveFileVO tradeApplicationApproveFileVO){
                logServiceUnavailable("修改交易申请审批文件", tradeApplicationApproveFileVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "修改交易申请审批文件失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<PageResp<LindiTradeApplicationApproveFileVO>> getPageTradeApplicationApproveFileList(
                    TradeApplicationApproveFileQueryVO queryVO){
                logServiceUnavailable("分页查询交易申请审批文件列表", queryVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "分页查询交易申请审批文件列表失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<LindiTradeApplicationApproveFileVO> getTradeApplicationApproveFileByApproveFileId(
                    Long approveFileId){
                logServiceUnavailable("获取交易申请审批文件详情", approveFileId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "获取交易申请审批文件详情失败，服务不可用: " + cause.getMessage());
            }
        };
    }
}
